<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>
<style>
.ordercount{
	width:100%;
    display: inline-flex;
}
.samestatic{
	width:309px;
	height:150px;
	margin-top:10px;
	margin-left:77px;
}
.samestatic:nth-child(1){
	margin-left:0px;
}
.ordersty{
	background:#1f95ef;
}
.balance{
	background:#45b854;
}
.customer{
	background:#f86b67;
}
.sametitle{
	color: #fff;
    font-size: 16px;
    margin-left: 20px;
    margin-top: 10px;
}
.sameorderinfo{
	color: #fff;
    margin-left: 35px;
    line-height:20px;
}
.summer-datagrid-cell{
	text-align:center;
}
.top-batch{
    width:80px;
	height:34px;
	text-align:center;
}
/*******批量备注*******/
.remarkcon{
    height: 77px;
    background: #fff;
    border: solid 1px #e1e6eb;
    border-bottom: 0;
}
.remarkbut{
	width:114px;
	height:34px;
	border:solid 1px #f86b67;
	line-height:34px;
	text-align:center;
	color:#f86b67;
	margin:20px;
	cursor:pointer;
}
.smallremark{
	color: #1f95ef;
    font-size: 10px;
    margin-left: 7px;
}
.copybut{
	color:#0474c8;
	margin-left: 5px;
	cursor:pointer;
    margin-right: 8px;
}
/***按钮选中态****/
.pitchbut{
	background:#f86b67;
	color:#fff;
}
/*******表格样式*********/
.proleft{
  float:left;
  margin-top: 2px;
  width: 33%;
}
.proleft>img{
  width:84px;
  height:84px;
}
.proright{
  float:left;
  margin-left:2px;
  margin-top: 2px;
  text-align: left;
      width: 66%;
  
}
.sametr{
	height: 110px;
    border-bottom: solid 1px #999;
}
.summer-top{
	padding:0px !important;
}
/*******head******/
.headcon{
    width: 100%;
    border-bottom: solid 1px #0288d1;
}
.top-batch{
	width:100%;
	line-height:34px;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
    </span>
    <span class="field-cont">
        <span class="field-cont-title">售后编号</span>
        <input type="text" class="summer-input" id="id" />
        <input type="hidden" class="summer-input" id="dealState" value="001"/>
    </span>

    <span class="field-cont">
        <span class="field-cont-title">运单号</span>
        <input type="text" class="summer-input" id="expressNo" />
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">申请类型</span>
        <input type="text" class="summer-input" id="type" />
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">买家昵称/ID</span>
        <input type="text" class="summer-input" id="userInfo" />
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">开始时间</span>
	    <input type="text" id="createTime" name="createTime" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">结束时间</span>
	    <input type="text" id="endTime" name="endTime" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>
<table class="summer-datagrid" style="width:auto">
	
	    <thead class="orderhead">
	    	<tr>
	    		<th style="width:100px;"><div class="top-batch"><a id="toAll" href="javascript:;">全部</a></div></th>
	    		<th  style="width:100px;"><div class="top-batch"><a id="toDeal" href="javascript:;">待处理</a></div></th>
	    		<th  style="width:100px;"><div class="top-batch"><a id="toAgree" href="javascript:;">同意</a></div></th>
	    		<th  style="width:120px;"><div class="top-batch"><a id="toRefuse" href="javascript:;">拒绝</a></div></th>
	    		<th  style="width:120px;"><div class="top-batch  pitchbut"><a id="toRefund" href="javascript:;">退款</a></div></th>
	    	</tr>
	    </thead>		
	</table>
	<div class="remarkcon">
		<div class="remarkbut" id="confirmRefund"><a>确认退款</a></div>
	</div>
<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="10%">
	    <col width="30%">
	    <col width="20%">
	    <col width="20%">
	    <col width="10%">
	    <col width="30%">
	    <col width="20%">
	    <col width="16%">
	    <col width="20%">
	    <col width="20%">
	    <thead>
		    <tr>
		    	<th><input type="checkbox" id="checkAll">全选</th>
		    	<th>售后编号</th>
		        <th>商品名称</th>
		        <th>申请时间</th>
		        <th>金额</th>
		        <th>买家昵称/ID</th>
		        <th>申请类型</th>
		        <th>申请原因</th>
		        <th>处理状态</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
			LIST: basePath + '${common_url}list',
			INIT_EDIT: basePath + "${common_url}initEdit",
			AGREE: basePath + "${common_url}agree",
			REFUSE: basePath + "${common_url}refuse",
			INIT_VIEW: basePath + "${common_url}initView",
			TO_AGREE: basePath + "${common_url}toAgree",
			TO_REFUSE: basePath + "${common_url}toRefuse",
			TO_REFUND: basePath + "${common_url}toRefund",
			TO_ALL: basePath + "${common_url}init",
			CONFIRM_REFUND: basePath + "${common_url}confirmRefund",
			TO_DEAL: basePath + "${common_url}toDeal"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	 //下拉初始化
   	     $('#type').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_T_ORDERS_AFTERSALE_TYPE'
         });
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        
		
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        $('#toAgree').on('click',toAgree);
        $('#toRefuse').on('click',toRefuse);
        $('#toRefund').on('click',toRefund);
        $('#toAll').on('click',toAll);
        $('#toDeal').on('click',toDeal);
        $('#confirmRefund').on('click',confirmRefund);
    	$('#checkAll').on('click',checkAll);
      //编辑
    	//$('#funcbar').on('click', 'a[data-permit="${name_english}:initEdit"]', update);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#id').val('');
        	$('#expressNo').val('');
        	$('#userId').val('');
        	$('#createTime').val('');
        	$('#updateTime').val('');
        	$('#type').combobox('clear');
        	reloadTable();
        });
       createTable();
     //编辑
       $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
           var $this = $(this),
               id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
          	   skuId = $this.closest('tr').find('td[data-field="skuId"]').attr('data-value');
          	   userId = $this.closest('tr').find('td[data-field="userId"]').attr('data-value');
           window.location.href = CONST_URL.INIT_EDIT + '?skuId=' + skuId+'&id='+id+'&userId='+userId;
       });	
     //同意
      $('#t-wrap').on('click', 'a[data-permit="${name_english}:agree"]', function() {
			var $this = $(this),
		    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
			type: 'confirm',
			msg: '您确定要审核通过该记录吗?',
			onConfirm: function(result) {
			    if (result) {
			    	$.sajax({
		                url : CONST_URL.AGREE + "?id=" + id,
		                onLoadSuccess : function() {
		                	 $.stip({
            	                type:'ok',//显示类型 有info、 ok、 danger
            	                text: '审核成功！'    
		                	});
		                	reloadTable();  
		                }
		            });
			    		
			    }	
			}
		});
	});
      
     //拒绝
     $('#t-wrap').on('click', 'a[data-permit="${name_english}:refuse"]', function() {
			var $this = $(this),
		    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
			type: 'confirm',
			msg: '您确定要拒绝通过该记录吗?',
			onConfirm: function(result) {
			    if (result) {
			    	$.sajax({
		                url : CONST_URL.REFUSE + "?id=" + id,
		                onLoadSuccess : function() {
		                	 $.stip({
            	                type:'ok',//显示类型 有info、 ok、 danger
            	                text: '拒绝成功！'    
		                	});
		                	reloadTable();  
		                }
		            });
			    		
			    }	
			}
		});
	});
     //查看详情
      $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
          var $this = $(this),
              id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
          window.location.href = CONST_URL.INIT_VIEW + '?id=' + id;
      });	
       
    });
    function checkAll(){
		 $("[name='id']").attr("checked",'true');//全选 
	}
    //批量确认收货
    function tobatchdel(){
	}
    function toAgree(){
    	window.location.href = CONST_URL.TO_AGREE;
    }
    function toRefuse(){
    	window.location.href = CONST_URL.TO_REFUSE;
    }
    function toRefund(){
    	window.location.href = CONST_URL.TO_REFUND;
    }
    function toDeal(){
    	window.location.href = CONST_URL.TO_DEAL;
    }
    function toAll(){
    	window.location.href = CONST_URL.TO_ALL;
    }
    function confirmRefund(){
		var id = $("input[name='id']:checked").serialize();
		$.sdialog({
			type : 'confirm',
			msg : '您确定要确认退款吗?',
			onConfirm : function(result) {
				if (result) {
					$.sajax({
						url : CONST_URL.CONFIRM_REFUND + "?id=" + id,
						onLoadSuccess : function() {
							$.stip({
								type : 'ok',//显示类型 有info、 ok、 danger
								text : '确认成功！'
							});
							reloadTable();
						}
					});

				}
			}
		});
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"id": trimSpace($('#id').val()),
            		"expressNo" : trimSpace($('#expressNo').val()),
    				"userId":trimSpace($('#userInfo').val()),
    				"createTime":trimSpace($('#createTime').val()),
    				"updateTime":trimSpace($('#endTime').val()),
    				"type":$('#type').combobox('getValue'),
    				"dealState":trimSpace($('#dealState').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"id": trimSpace($('#id').val()),
    				"expressNo" : trimSpace($('#expressNo').val()),
    				"userId":trimSpace($('#userInfo').val()),
    				"createTime":trimSpace($('#startTime').val()),
    				"updateTime":trimSpace($('#endTime').val()),
    				"type":$('#type').combobox('getValue'),
    				"dealState":trimSpace($('#dealState').val())
            	}
    		},
    		columns: [
    			 {
   		    	 	field: 'skuId',
   		    	 	hidden: true
   		    	 },
   		    	 {
    		    	field: 'userId',
    		    	hidden: true
    		     },
    		     {
						render : function(rowData){
							return '<input type="checkbox" id="id" name="id" value="'+rowData.id+'">';
						}
					},
    		     {
    		    	 field: 'id',
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<p>'+rowData.goodsName+'</p>'+
    		    		 '<p>（商品数量：'+rowData.count+'）</p>';
    		    		 }
    		     },
    		     {
    		    	 field:'createTime'
    		     },
    		     {
    		    	 field:'amount'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<p>用户ID：'+rowData.userId+'</p>'+
    		    		 '<p>用户姓名：'+rowData.userNickName+'</p>';
    		    		 }
    		     },
    		     {
    		    	 field:'type'
    		     },
    		     {
    		    	 field:'applyReason'
    		     },
    		     {
    		    	 field:'dealState'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 if(rowData.dealState == "待处理"){
    		    			 if(rowData.type == "换货"){
        		    			 return $.funcbar({
            		    			 data: permission,    //请求的数据
            		    			 type: 'text',     //类型
            		    			 display: 4,    //显示数量
            		    			 permit: ['${name_english}:agree',//同意
            		    				 	  '${name_english}:refuse',//拒绝
            		    				 	  '${name_english}:initEdit',//新建订单初始化
            		    				 	  '${name_english}:initView'] //查看详情
            		    			 
            		    		 });
        		    		 }else{
        		    			 return $.funcbar({
            		    			 data: permission,    //请求的数据
            		    			 type: 'text',     //类型
            		    			 display: 3,    //显示数量
            		    			 permit: ['${name_english}:agree',
            		    				 	  '${name_english}:refuse',
            		    				 	  '${name_english}:initView'] //需要的权限按钮
            		    			 
            		    		 });
        		    		 }
    		    		 }else{
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 1,    //显示数量
        		    			 permit: ['${name_english}:initView'] //需要的权限按钮
        		    			 
        		    		 });
    		    		 }
    		    		 
    		    		 
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
    
   
</script>
</body>
</html>